package com.billionsfinance.hessian.db.impl;

import com.billionsfinance.hessian.core.ClientInfo;
import com.billionsfinance.hessian.db.HessianClientDao;
import com.billionsfinance.hessian.db.core.StrategyBaseDao;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author WeiHui.Zhang
 * @version V1.00
 * @fileName: HessianClientDao.java
 * @date 2016年7月25日 下午5:21:55
 */
public class HessianClientDaoImpl extends StrategyBaseDao implements HessianClientDao {

	@Override
	public List<ClientInfo> findAll() {
		String sql = "SELECT * FROM HESSIAN_CLIENT;";
		PreparedStatement pstmt = execQuery(sql);
		ResultSet rs = null;
		List<ClientInfo> infos = null;
		if (pstmt != null) {
			infos = new ArrayList<>();
			try {
				rs = pstmt.executeQuery();
				while (rs.next()) {
					ClientInfo tempInfo = new ClientInfo();
					tempInfo.setAppCode(rs.getString("APP_CODE"));
					tempInfo.setInterfaceName(rs.getString("INTERFACE_NAME"));
					tempInfo.setGroupNo(rs.getString("GROUP_NO"));
					tempInfo.setAccessUrl(rs.getString("ACCESS_URL"));
					infos.add(tempInfo);
				}
			} catch (SQLException e) {
				LOGGER.error("执行出错" + sql, e);
			} finally {
				closeConn(pstmt, rs);
			}
		}
		return infos;
	}

}